package com.scgl.depot.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.scgl.depot.domain.Depot;
import com.scgl.depot.service.IDepotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 仓库Controller
 *
 * @author mobai
 * @date 2024-10-25
 */
@RestController
@RequestMapping("/depot")
public class DepotController extends BaseController
{
    @Autowired
    private IDepotService depotService;

    /**
     * 查询仓库列表
     */
    @RequiresPermissions("depot:depot:list")
    @GetMapping("/list")
    public TableDataInfo list(Depot depot)
    {
        startPage();
        List<Depot> list = depotService.selectDepotList(depot);
        return getDataTable(list);
    }

    /**
     * 导出仓库列表
     */
    @RequiresPermissions("depot:depot:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, Depot depot)
    {
        List<Depot> list = depotService.selectDepotList(depot);
        ExcelUtil<Depot> util = new ExcelUtil<Depot>(Depot.class);
        util.exportExcel(response, list, "仓库数据");
    }

    /**
     * 获取仓库详细信息
     */
    @RequiresPermissions("depot:depot:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(depotService.selectDepotById(id));
    }

    /**
     * 新增仓库
     */
    @RequiresPermissions("depot:depot:add")
    @PostMapping
    public AjaxResult add(@RequestBody Depot depot)
    {
        depot.setCreateTime(new Date());
        return toAjax(depotService.insertDepot(depot));
    }

    /**
     * 修改仓库
     */
    @RequiresPermissions("depot:depot:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody Depot depot)
    {
        depot.setCreateTime(new Date());
        return toAjax(depotService.updateDepot(depot));
    }

    /**
     * 删除仓库
     */
    @RequiresPermissions("depot:depot:remove")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(depotService.deleteDepotByIds(ids));
    }
}
